<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>window</title>
</head>
<body>
    <h1>全局window对象
    </h1>
    <h2>实现弹出窗口</h2>
    <script>
        //1.弹出警告
        alert('hello');
        //2.确认框
        var flag=confirm("do you confirm?")
        if(flag){
            console.log('i like it');
            
        }else{
            console.log('nonono');
            
        }
        //3.提示框
        var name=prompt('请输入姓名','例如 tom')  
        console.log(name);
        
        </script>
        <h2>定时器</h2>
        <p>javascript可以在时间间隔内执行 这就是所谓的定时事件</p>
        <ol>
            <li>setTimeOut{function，milliseconds}</li>
            <p>在等待指定的毫秒后执行函数</p>
            <li>setInterval{function，milliseconds}</li>
            <p>持续重复的执行该函数</p>
        </ol>
<h3>setTimeout</h3>
<button id="btn1">启动</button>
<button id="btn2">停止</button>
        <script>
//获得启动和停止按钮
var star = document.getElementById('btn1')
var stop = document.getElementById('btn2')
//声明定时器变量
var timer;
star.onclick=function(){
    //创建定时器
    timer=setTimeout(function(){
        console.log('hello');
        
    },5000)
}
stop.onclick=function(){
    //清楚定时器
    clearTimeout(timer)
}
        </script>
        <h3>setInterval</h3>
      <button id="btn3">启动1</button>
<button id="btn4">停止1</button>

<script>
    var star1=document.getElementById('btn3')
    var stop1=document.getElementById('btn4')

    var timer1;
    star1.onclick=()=>{
        timer1=setInterval(function(){
            console.log('hello setinteral');
        },3000)
    }
    stop1.onclick=()=>{
        clearInterval(timer1)
    }
</script>
</body>
</html>